package com.ckzp.core.util;


/**
 * Created by 51594 on 2022/7/27.
 */
public class HtmlUtil {


    public static String toHtmlInput(String str) {
        if (str == null) {
            return null;
        } else {
            String html = new String(str);
            html = StringUtil.replace(html, "&", "&amp;");
            html = StringUtil.replace(html, "<", "&lt;");
            html = StringUtil.replace(html, ">", "&gt;");
            return html;
        }
    }

    public static String toHtml(String str) {
        if (str == null) {
            return "";
        } else {
            String html = new String(str);
            html = toHtmlInput(html);
            html = StringUtil.replace(html, "\r\n", "\n");
            html = StringUtil.replace(html, "\n", "<br>\n");
            html = StringUtil.replace(html, "\t", "    ");
            html = StringUtil.replace(html, "  ", " &nbsp;");
            return html;
        }
    }

    public static String replaceParamHtml(String str) {
        if (str == null) {
            return "";
        } else {
            String html = new String(str);
            return html.trim();
        }
    }

    public static String decode(String value) {
        value = value.replace("<", "");
        value = value.replace(">", "");
        value = value.replace("\"", "");
        value = value.replace("\\", "");
        value = value.replace("script", "");
        value = value.replace("/", "");
        value = value.replace("%", "");
        value = value.replace(";", "");
        value = value.replace("+", "");
        value = value.replace("\u0001", "");
        value = value.replace("\u0002", "");
        value = value.replace("\u0003", "");
        value = value.replace("\u0004", "");
        value = value.replace("\u0005", "");
        value = value.replace("\u0006", "");
        value = value.replace("\u0007", "");
        value = value.replace("\b", "");
        value = value.replace("\t", "");
        value = value.replace("\n", "");
        value = value.replace("\u000b", "");
        value = value.replace("\f", "");
        value = value.replace("\r", "");
        value = value.replace("\u000e", "");
        value = value.replace("\u000f", "");
        value = value.replace("\u0010", "");
        value = value.replace("\u0011", "");
        value = value.replace("\u0012", "");
        value = value.replace("\u0013", "");
        value = value.replace("\u0014", "");
        value = value.replace("\u0015", "");
        value = value.replace("\u0016", "");
        value = value.replace("\u0017", "");
        value = value.replace("\u0018", "");
        value = value.replace("\u0019", "");
        value = value.replace("\u001a", "");
        value = value.replace("\u001b", "");
        value = value.replace("\u001c", "");
        value = value.replace("\u001d", "");
        value = value.replace("\u001e", "");
        value = value.replace("\u001f", "");
        return value;
    }

    public static String toNospance(String str) {
        if (str == null) {
            return "";
        } else {
            String html = new String(str);
            html = toHtmlInput(html);
            html = StringUtil.replace(html, "\r\n", "\n");
            html = StringUtil.replace(html, "\n", "");
            html = StringUtil.replace(html, "\t", "");
            html = StringUtil.replace(html, "\r", "");
            html = StringUtil.replace(html, "  ", "");
            return html.trim();
        }
    }

}
